Repository navigation
Let a subclass of LRUEngineCache that skips its constructor read and write - #303
Merged
Merged
Conversation
…write LRUEngineCache gained a lock in its constructor. A subclass whose own constructor sets the cache without calling that constructor had no lock, so its first read or write raised AttributeError. The lock is now made on first use when the constructor did not make it, once per cache however many threads ask at the same time. Two tests cover a subclass that skips the constructor. Both fail without the change.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
#301 gave
LRUEngineCachea lock, made in its constructor, so that requests on several threads can share one cache. A subclass whose own constructor setsself.cachewithout calling the constructor ofLRUEngineCachehad no lock, so its first read or write raisedAttributeError. The same subclass worked before #301.Change
pipeline/fiftyone_pipeline_engines/src/fiftyone_pipeline_engines/lru_cache.py_get_lockgives the cache's lock. When the constructor did not make one, it makes it on first use, under a lock the class holds only while making it, so every thread of one cache shares the same lock.get_cache_valueandset_cache_valuehold the lock_get_lockgives.Tests
pipeline/fiftyone_pipeline_engines/tests/test_lru_cache.pyadds a subclass that sets its cache itself and skips the constructor.test_a_subclass_that_skips_the_constructor_reads_and_writeswrites and reads one value.test_its_threads_share_one_lock_made_on_first_useruns eight threads on one such cache, with a cache that records how many threads are inside it at once, and expects one.Both fail without the change, with
AttributeError. On Windows with Python 3.12, thefiftyone_pipeline_enginestests give 175 passed, which is the 173 before this change and the 2 new ones.No version change and no
+semverline.